package com.zhuang.arraylist.cloneDemo;

public class Student implements Cloneable {
	// 姓名
	private String name;
	// 年龄
	private int age;
	// 技能
	private Skill skill;

	public Student() {
	}

	public Student(String name, int age, Skill skill) {
		this.name = name;
		this.age = age;
		this.skill = skill;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public Skill getSkill() {
		return skill;
	}

	public void setSkill(Skill skill) {
		this.skill = skill;
	}

	@Override
	public String toString() {
		return "Student{" + "name='" + name + '\'' + ", age=" + age + ", skill=" + skill + '}';
	}

	/*
	 * 注意: 首先方法的权限修饰符需要更改为public 方法的返回值可以更改为当前类的类名
	 */
	@Override
	public Object clone() throws CloneNotSupportedException {
		// 调用超类Object中方法clone进行对象克隆,得到一个新的学生对象
		Student newStu = (Student) super.clone();
		// 调用学生类其属性skill的clone方法,对属性进行克隆
		Skill s = this.skill.clone();
		// 再将克隆的Skill设置给克隆出来的学生对象
		newStu.setSkill(s);
		// 返回克隆出来的学生对象
		return newStu;
	}

}
